FROM maven:3.9.0-eclipse-temurin-8 AS overlay

RUN mkdir -p cas-overlay \
    && mkdir -p cas-overlay/src \
    && mkdir -p cas-overlay/.mvn/wrapper

COPY ./mvnw ./pom.xml /cas-overlay/
COPY ./src /cas-overlay/src/

RUN cd /cas-overlay \
    && mvn -N io.takari:maven:wrapper

COPY ./.mvn/wrapper/ /cas-overlay/.mvn/wrapper/

RUN cd /cas-overlay \
    && cat ./.mvn/wrapper/maven-wrapper.properties \
    && chmod 750 ./mvnw \
    && ./mvnw --version;

ENV MAVEN_CONFIG=

RUN cd /cas-overlay \
    && ./mvnw clean package -T 5;

FROM openjdk:8-jdk AS cas

LABEL "Organization"="Apereo"
LABEL "Description"="Apereo CAS"

RUN cd / \
    && mkdir -p /etc/cas/config \
    && mkdir -p cas-overlay;

COPY --from=overlay cas-overlay/target/cas.war cas-overlay/
COPY etc/cas/ /etc/cas/
COPY etc/cas/config/ /etc/cas/config/

EXPOSE 8080 8443

ENV PATH $PATH:$JAVA_HOME/bin:.

WORKDIR cas-overlay
ENTRYPOINT ["java", "-server", "-noverify", "-Xmx2048M", "-Dhttps.protocols=TLSv1", "-Djava.security.egd=file:/dev/./urandom", "-jar", "cas.war"]
